﻿using Kw.Combinatorics;
using System;

namespace Kw.CombinatoricsExamples
{
    // Subclassing is one way to get user-friendly output.
    public class LettersXYZ : Multicombination
    {
        public static readonly string[] letters = new string[] { "X", "Y", "Z" };

        public LettersXYZ (int k) : base (letters.Length, k)
        { }

        public override string ToString ()
        {
            string result = "";
            foreach (int element in this)
                result += letters[element];
            return result;
        }
    }

    class MulticombinationExample02
    {
        static void Main ()
        {
            LettersXYZ multicombo = new LettersXYZ (4);

            for (int k = 1; k <= multicombo.Picks; ++k)
                foreach (LettersXYZ row in multicombo.GetRows (k, 0))
                    Console.WriteLine ("Rank {0,2}: {1}", row.Rank, row);
        }

        /* Output:

        Rank  0: X
        Rank  1: Y
        Rank  2: Z
        Rank  0: XX
        Rank  1: XY
        Rank  2: XZ
        Rank  3: YY
        Rank  4: YZ
        Rank  5: ZZ
        Rank  0: XXX
        Rank  1: XXY
        Rank  2: XXZ
        Rank  3: XYY
        Rank  4: XYZ
        Rank  5: XZZ
        Rank  6: YYY
        Rank  7: YYZ
        Rank  8: YZZ
        Rank  9: ZZZ
        Rank  0: XXXX
        Rank  1: XXXY
        Rank  2: XXXZ
        Rank  3: XXYY
        Rank  4: XXYZ
        Rank  5: XXZZ
        Rank  6: XYYY
        Rank  7: XYYZ
        Rank  8: XYZZ
        Rank  9: XZZZ
        Rank 10: YYYY
        Rank 11: YYYZ
        Rank 12: YYZZ
        Rank 13: YZZZ
        Rank 14: ZZZZ

        */
    }
}
